package com.foreknow.mapping;

import com.foreknow.db.DBManager;

import java.util.HashMap;
import java.util.Map;

public class MappingFactory {
    private static MappingFactory mappingFactory = null;
    //创建一个Map容器用于保存xxxMapping
    private Map<String,EntityMapping> maps = new HashMap<>();
    public static final String USER_MAPPING = "userMapping";
    public static final String GUESTBOOK_MAPPING = "guestbookMapping";
    private MappingFactory(){
    }

    public static MappingFactory getInstance() {
        if (mappingFactory == null) {
            mappingFactory = new MappingFactory();
            mappingFactory.maps.put(USER_MAPPING,new UserMapping());
            mappingFactory.maps.put(GUESTBOOK_MAPPING,new GuestbookMapping());
            //mappingFactory.maps.put("xxxMapping",new xxxMapping());
        }
        return mappingFactory;
    }

    /**
     * 从Map集合中获取元素
     */
    public EntityMapping getmapping(String key) {
        return maps.get(key);
    }
}
